<?php

/**
 * This is the model class for table "tbl_user_active".
 *
 * The followings are the available columns in table 'tbl_user_active':
 * @property string $id
 * @property string $user_id
 * @property integer $active_type
 * @property string $image_id
 * @property string $collection_id
 * @property string $active_at
 *
 * The followings are the available model relations:
 * @property User $user
 * @property Image $image
 * @property Collection $collection
 */
class UserActive extends CActiveRecord {

    const LIKE_IMG = 0;
    const UPLOAD_IMG = 1;
    const COMMENT_IMG = 2;
    const ADD_IMG_TO_COLLECTION = 3;
    const LIKE_COLLECTION = 4;
    const COMMENT_COLLECTION = 5;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return UserActive the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'tbl_user_active';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('user_id, active_type, active_at', 'required'),
            array('active_type', 'numerical', 'integerOnly' => true),
            array('user_id, image_id, collection_id', 'length', 'max' => 20),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, user_id, active_type, image_id, collection_id, active_at', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'user' => array(self::BELONGS_TO, 'User', 'user_id'),
            'image' => array(self::BELONGS_TO, 'Image', 'image_id'),
            'collection' => array(self::BELONGS_TO, 'Collection', 'collection_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'user_id' => 'User',
            'active_type' => 'Active Type',
            'image_id' => 'Image',
            'collection_id' => 'Collection',
            'active_at' => 'Active At',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('user_id', $this->user_id, true);
        $criteria->compare('active_type', $this->active_type);
        $criteria->compare('image_id', $this->image_id, true);
        $criteria->compare('collection_id', $this->collection_id, true);
        $criteria->compare('active_at', $this->active_at, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}